﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;
using CommonLib;
using BLL.System;

namespace Haolaike.ashx.System
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class hParam : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request.QueryString["action"];
            string result = string.Empty;
            int? pageSize = null;
            if (!string.IsNullOrEmpty(context.Request["rows"])) pageSize = Convert.ToInt32(context.Request["rows"]);
            int? pageNum = null;
            if (!string.IsNullOrEmpty(context.Request["rows"])) pageNum = Convert.ToInt32(context.Request["page"]);
            Dictionary<string, string> dicLike = new Dictionary<string, string>();
            Dictionary<string, string> dicEqual = new Dictionary<string, string>();

            try
            {
                if (context.Session["user"] == null) throw new Exception("登录超时！");
                ParamBO bo = new ParamBO();
                UserBO ubo = new UserBO();

                switch (action)
                {
                    case "get":
                        dicLike.Add("PARAM_TYPE", context.Request["sPARAM_TYPE"]);
                        dicLike.Add("PARAM_CODE", context.Request["sPARAM_CODE"]);
                        dicLike.Add("PARAM_NAME", context.Request["sPARAM_NAME"]);
                        if (context.Request["userkey"] != null) dicEqual.Add("ug.USER_KEY", context.Request["userkey"]);
                        result = bo.getParam(dicLike, dicEqual, pageSize, pageNum);
                        break;
                    case "add":
                        //
                        result = bo.addParam(context);
                        break;
                    case "edit":
                        //
                        result = bo.editParam(context);
                        break;
                    case "del":
                        //删除
                        result = bo.deleteParam(context);
                        break;
                    case "revert":
                        //删除重新返回
                        result = bo.revertParam(context);
                        break;
                    case "loginlog":
                        ubo.addLoginLog(context);
                        break;
                    case "getParamType":
                        result = bo.getParamType(context);
                        break;
                }
            }
            catch (Exception ex)
            {
                var error = new Entities.Status { Success = false, Message = ex.Message };
                result = error.ToJson();

            }
            finally
            {
                context.Response.Write(result);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
